import Mock from "mockjs";
import { MockMethod } from "vite-plugin-mock";
import contextPath from "../../context-path";
import adminRouters from "./_routers";
import demoRouters from "../demo/_routers";

// import lockerRouters from "../locker/routers";
const Random = Mock.Random;
const routers = Array<any>();

// lockerRouters.forEach((item) => {
//   routers.push(item);
// });

adminRouters.forEach((item) => {
  routers.push(item);
});

Mock.Random.extend({
  phone: function () {
    var phonePrefixs = ["138", "135", "189"]; // 自己写前缀哈
    return this.pick(phonePrefixs) + Mock.mock(/\d{8}/); //Number()
  },
});

export default [
  {
    url: contextPath.VITE_API_AUTH_CONTEXT_PATH + "/auth/v1/public.key.get",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: "0458fff93bae370c643a8375d042966353cc8d055011104c5dab3ffbeb5c40e356689b1a8a59ad0fa41ef3f95e05400b6045d2ea58a1c916722d7fc06605c0a4b3",
      };
    },
  },
  {
    url: contextPath.VITE_API_AUTH_CONTEXT_PATH + "/auth/v1/login.captcha",
    method: "get",
    response: (options) => {
      return Random.image("100x50", "#02adea", "Hello");
    },
  },
  {
    url: contextPath.VITE_API_AUTH_CONTEXT_PATH + "/auth/v1/login.by.account",
    method: "post",
    response: (options) => {
      console.log("/auth/v1/login.by.account", options.body);
      if (options.body.account == "test500") {
        return {
          code: 200401,
          message: "账号密码错误",
          data: null,
        };
      }
      return {
        code: 200,
        message: "",
        data: {
          accountId: Random.guid(),
          account: {
            accountId: Random.guid(),
            account: Random.email(),
            name: Random.cname(),
            gender: Mock.mock({
              "array|1": [0, 1, 2],
            }).array,
            employeeNumber: Random.natural(),
            orgName: Random.region(),
            orgCode: Random.string("upper", 5),
            deptName: Random.city(),
            deptCode: Random.string("upper", 5),
            mobile: Random.phone(),
          },
          roleList: [
            { roleCode: "ROLE_ADMIN", roleName: "系统管理员" },
            { roleCode: "ROLE_LOG_ADMIN", roleName: "系统日志管理员" },
          ],
          tokenInfo: { token: Random.guid(), expires: 7200 },
        },
      };
    },
  },
  {
    url: contextPath.VITE_API_AUTH_CONTEXT_PATH + "/auth/v1/logout",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },

  {
    url:
      contextPath.VITE_API_AUTH_CONTEXT_PATH +
      "/portal/v1/menu.item.current.listing",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: routers,
      };
    },
  },
] as MockMethod[];
